let db = require("../db/index");

// 商铺查询
exports.shoplist = (req, res) => {
    var sql =
        `select * from shopmengment `;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 根据id查询
exports.shoplistselect = (req, res) => {
    var sql =
        `select * from shopmengment where date=${req.query.date}`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 修改商铺管理数据
exports.shoplistupdate = (req, res) => {
    console.log(req.body)
    var sql =
        `update shopmengment set Belongingcommunity='${req.body.communityName}',Productarea="${req.body.Shoparea}",ShopNumber="${req.body.ShopNumber}",Floorlocation=${req.body.Floor},buildingarea="${req.body.buildingarea}",usablearea="${req.body.usablearea}",Housetype="${req.body.Housetype}",Housingstatus="${req.body.Housingstatus}" where date=${req.body.date}`;
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
// exports.shoplistupdate = (req, res) => {
//     console.log(req)
//     var sql =
//         `update shopmengment set edit="绑定业主",Belongingcommunity='${req.body.communityName}',Productarea='${req.body.Shoparea}' where date=${req.body.date}`;
//     db.query(sql, [], (err, data) => {
//         console.log(sql)
//         if (err) {
//             console.log("出错了", err);
//             return res.send("错误" + err.message);
//         }
//         res.send({
//             data,
//             state:200
//         });
//     });
// };
// 添加商铺数据
exports.shoplistinsert = (req, res) => {
    var sql =
        `insert into shopmengment(Belongingcommunity,Productarea,ShopNumber,Floorlocation,buildingarea,usablearea,Housetype,Housingstatus,edit,del,opertes) values('${req.body.communityName}',"${req.body.Shoparea}","${req.body.ShopNumber}",${req.body.Floor},"${req.body.buildingarea}","${req.body.usablearea}","${req.body.Housetype}","${req.body.Housingstatus}","绑定业主","编辑","删除")`;
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};

// 删除商铺数据
exports.shoplistdel = (req, res) => {
    var sql = `delete from shopmengment where date = ${req.body.date}`;
    db.query(sql, [req.body.id], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err);
        }
        res.send({
            data,
            state:200
        });
    });
};